import asyncio
import aiohttp

import os

TEMP_PATH = os.path.join(os.path.abspath(os.path.join(os.getcwd(),"..")), 'temp')
async def download(session,url):
    print("开始下载,",url)
    async with session.get(url,verify_ssl=False) as rs:
        if rs.status == 200:
            filename =os.path.join(TEMP_PATH,url.split('/')[-1])
            content = await rs.content.read()
            with open(filename,'wb') as f:
                f.write(content)
                print("下载结束,", url)
        else:
            print("下载失败")

async def main():
    urls = [
        'https://17dz.com/home/images/auto-1.png',
        'https://17dz.com/home/images/auto-2.png',
        'https://17dz.com/home/images/auto-3.png'
    ]
    async with aiohttp.ClientSession() as session:
        tasks = [asyncio.create_task(download(session,url)) for url in urls]
        await asyncio.wait(tasks)


if __name__ == "__main__":
    asyncio.run(main())

    